# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer:
# TODO: Build csv-lwt (?).
pkgname=ocaml-csv
_pkgname=csv
pkgver=2.2
pkgrel=1
pkgdesc="OCaml library for reading and writing CSV files"
url="https://github.com/Chris00/ocaml-csv"
arch="all !x86 !armhf !armv7 !s390x !mips !mips64"  # limited by ocaml abuild
license="LGPL-2.1-or-later"
depends="ocaml-runtime"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="dune ocaml ocaml-findlib opam"
subpackages="$pkgname-dev csvtool"
source="$pkgname-$pkgver.tar.bz2::https://github.com/Chris00/$pkgname/releases/download/$pkgver/csv-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
options="textrels !check"  # FIXME check requires package lwt

build() {
	dune build -p csv @install
}

package() {
	mkdir -p "$pkgdir"/usr/lib/ocaml
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml \
		csv

	cd "$pkgdir"

	# Remove annotation files, some generated code (?) and sources.
	find usr/lib/ocaml \
		-name '*.cmt' -delete \
		-o -name '*.cmti' -delete \
		-o -name '*.ml-gen' -delete \
		-o -name '*.ml' -delete

	# Contains just a readme and changelog.
	rm -Rf usr/doc
}

dev() {
	local sitelib="usr/lib/ocaml/$_pkgname"

	default_dev

	cd "$pkgdir"/$sitelib
	mkdir -p "$subpkgdir"/$sitelib
	mv *.cmx *.cmxa *.mli "$subpkgdir"/$sitelib/
}

csvtool() {
	pkgdesc="A command line tool for handling CSV files"
	depends=""

	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

sha512sums="f9db9f2b9934ba568c6546fc0ebbfcff7de9f3383b619a5bc49566bbbca37d8fc1ae967014012b9bf547ffd04911888df3c588bdefc0f24ce4869353f4f10207  ocaml-csv-2.2.tar.bz2"
